
var _util = require('util/util.js')

var _cart_service = {
    getCartItemList: function (resolve, reject) {
        _util.request({
            url: _util.getServerURL('/cart/cartitems'),
            method: 'GET',
            success: resolve,
            error: reject
        });
    },
    removeCartItem: function (itemId, resolve, reject) {
        _util.request({
            url: _util.getServerURL('/cart/cartitems/' + itemId),
            method: 'DELETE',
            success: resolve,
            error: reject
        });
    },
    addToCart: function (itemId, resolve, reject, content) {
        _util.request({
            url: _util.getServerURL('/cart/cartitems/' + itemId),
            method: 'POST',
            success: resolve,
            error: reject,
            data: content
        });
    },
    clearCart: function (resolve, reject, content) {
        _util.request({
            url: _util.getServerURL('/cart/cartitems/clear'),
            method: 'POST',
            success: resolve,
            error: reject,
            data: content
        });
    },
    updateCart: function (itemId, resolve, reject, content) {
        _util.request({
            url: _util.getServerURL('/cart/cartitems/' + itemId),
            method: 'PUT',
            success: resolve,
            error: reject,
            data: content
        });
    },
    getItemattrs: function (itemId, resolve, reject) {
        _util.sync_request({
            url: _util.getServerURL('/catalog/items/' + itemId + '/attributes'),
            method: 'GET',
            success: resolve,
            error: reject,
        });
    },
    getcoupons: function (resolve, reject) {
        _util.request({
            url: _util.getServerURL('/coupon/coupons'),
            method: 'GET',
            success: resolve,
            error: reject,
        });
    },
    getCartNums: function (resolve, reject) {
        _util.request({
            url: _util.getServerURL('/cart/cartitems/num'),
            method: 'GET',
            success: resolve,
            error: reject,
        });
    }
};

module.exports = _cart_service;

